home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / ProjectDrag 1.1b4 / Sources / ProjectDrag Sources / CheckOut.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-07  |  3.8 KB  |  163 lines  |  [TEXT/MPS ]

  1. /* CheckOut.c: CheckOut applet for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "Comments.h"
  20. #include "TasksAndErrors.h"
  21.  
  22.  
  23. void CheckOutFile(FSSpec *file);
  24.  
  25.  
  26. /* This routine is called for each file passed in the ODOC event. */
  27.  
  28. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  29. {
  30. #pragma unused ( opening )
  31. #pragma unused ( userDataHandle )
  32.  
  33.     CheckOutFile(myFSSPtr);
  34. }
  35.  
  36.  
  37. void CheckOutFile(FSSpec *file)
  38. {
  39.     Str63 userName;
  40.     Str15 nickname;
  41.     OSErr err;
  42.     CKIDHandle theCKID;
  43.     AEDesc command;
  44.     Str255 comment;
  45.     Str255 projectName;
  46.  
  47.     TaskStart(2001, 1, file->name, NULL, NULL, NULL);
  48.     
  49.     /* find the user name and initials */
  50.     err = GetUserSettings(userName, nickname, false);
  51.     if (err != noErr)
  52.     {
  53.         gDone = true;
  54.         return;
  55.     }
  56.  
  57.     /* get the CKID */
  58.     err = ExtractCKID(file, &theCKID);
  59.     if (err != noErr)
  60.     {
  61.         RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
  62.                          NULL, NULL, NULL);
  63.         return;
  64.     }
  65.     
  66.     /* make sure the file is checked in */
  67.     if ((*theCKID)->writeable || (*theCKID)->modifyReadOnly)
  68.     {
  69.         DisposeHandle((Handle)theCKID);
  70.         RaiseErrorString(kProjectDragStrings, kNoCheckOutPermission, file->name,
  71.                          NULL, NULL, NULL);
  72.         return;
  73.     }
  74.  
  75.     /* get the checkout comment from the user */
  76.     comment[0] = 0;
  77.     if (!GetChangeComment(false, file->name, comment))
  78.     {
  79.         DisposeHandle((Handle)theCKID);
  80.         return;
  81.     }
  82.     
  83.     /* mount the project */
  84.     err = MountProjectFromCKID(theCKID, projectName);
  85.     if (err != noErr) return;
  86.     
  87.     /* create a CheckOut -m command for SourceServer
  88.      * CheckOut -m -cs <comment> -d <dir> -project <project> -u <user> <file>
  89.      */
  90.     err = CreateCommand(&command, "CheckOut");
  91.     if (err == noErr)
  92.         err = AddCStringArg(&command, "-m");
  93.     if (err == noErr)
  94.         err = AddCommentArg(&command, comment);
  95.     if (err == noErr)
  96.         err = AddDirArg(&command, file->vRefNum, file->parID);
  97.     if (err == noErr)
  98.         err = AddProjectArg(&command, projectName);
  99.     if (err == noErr)
  100.         err = AddUserArg(&command, userName);
  101.     if (err == noErr)
  102.         err = AddPStringArg(&command, file->name);
  103.     if (err != noErr)
  104.     {
  105.         AEDisposeDesc(&command);
  106.         RaiseErrorNumber(err);
  107.         return;
  108.     }
  109.     
  110.     err = SendCommand(&command);        /* send the command to SourceServer */
  111.     if (err != noErr) return;
  112.     
  113.     /* add the checkout comment to the file */
  114.     err = AddCheckoutComment(file, userName, nickname, comment);
  115.     if (err != noErr)
  116.     {
  117.         /* pop the current task and start a new one if user confirms cancel */
  118.         if (!ResTextYesNo(kProjectDragStrings, kCheckoutCommentFailedCancel,
  119.                          file->name, NULL, NULL, NULL))
  120.         {
  121.             RaiseErrorNumber(userCanceledErr);
  122.             return;
  123.         }
  124.         
  125.         TaskDone(); /* not really! */
  126.         
  127.         TaskStart(2001, 2, file->name, NULL, NULL, NULL);
  128.         
  129.         /* cancel the checkout */
  130.         err = CreateCommand(&command, "CheckOut");
  131.         if (err == noErr)
  132.             err = AddCStringArg(&command, "-cancel");
  133.         if (err == noErr)
  134.             err = AddCStringArg(&command, "-y");
  135.         if (err == noErr)
  136.             err = AddDirArg(&command, file->vRefNum, file->parID);
  137.         if (err == noErr)
  138.             err = AddProjectArg(&command, projectName);
  139.         if (err == noErr)
  140.             err = AddPStringArg(&command, file->name);
  141.         if (err != noErr)
  142.         {
  143.             AEDisposeDesc(&command);
  144.             RaiseErrorNumber(err);
  145.             return;
  146.         }
  147.  
  148.         err = SendCommand(&command);
  149.         if (err != noErr) return;
  150.     }
  151.     
  152.     TaskDone();
  153. }
  154.  
  155.  
  156. void DoFileMenu(short itemID)
  157. {
  158.     if ( itemID == 1 )
  159.         SelectFile();        // call file selection userProc
  160.     else
  161.         SendQuitToSelf();    // send self a 'quit' event
  162. }
  163.